<template>
  <div class="app-container">

    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>本公司信息</span>
        <el-button style="float: right; margin-bottom: 3px" type="primary" @click="handleEdit" v-if="disabledForm">编辑</el-button>
        <el-button style="float: right; margin-bottom: 3px" type="primary" @click="submitForm" v-if="!disabledForm">保 存</el-button>
        <el-button style="float: right; margin-bottom: 3px" @click="cancel" v-if="!disabledForm">取 消</el-button>
      </div>
      <div >
        <el-form ref="scmMyCompanyInfoRef" :model="form" :rules="rules" :disabled="disabledForm" label-width="80px">
          <el-row :gutter="24">
            <el-col :span="8">
              <el-form-item label="公司全称" prop="name">
                <el-input v-model="form.name" placeholder="请输入公司全称" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="简称" prop="shortName">
                <el-input v-model="form.shortName" placeholder="请输入简称" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="统一社会信用代码" prop="registerNo" label-width="150px">
                <el-input v-model="form.registerNo" placeholder="请输入统一社会信用代码" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="24">
            <el-col :span="8">
              <el-form-item label="开户银行" prop="bankName">
                <el-input v-model="form.bankName" placeholder="请输入开户行名称" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="银行账号" prop="bankAccount">
                <el-input v-model="form.bankAccount" placeholder="请输入开户账号" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="税号" prop="taxNo" label-width="150px">
                <el-input v-model="form.taxNo" placeholder="请输入税号" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="24">
            <el-col :span="8">
              <el-form-item label="联系人" prop="contactName">
                <el-input v-model="form.contactName" placeholder="请输入联系人名称" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="联系电话" prop="phone">
                <el-input v-model="form.phone" placeholder="请输入联系电话" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="邮箱" prop="email" label-width="150px">
                <el-input v-model="form.email" placeholder="请输入邮箱" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row :gutter="24">
            <el-col :span="8">
              <el-form-item label="地址" prop="address">
                <el-input v-model="form.address" placeholder="请输入地址" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="备注" prop="remarks">
                <el-input v-model="form.remarks" placeholder="请输入备注" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
            </el-col>
          </el-row>
        </el-form>

      </div>
    </el-card>

<!--    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">-->
<!--      <el-form-item label="公司全称" prop="name">-->
<!--        <el-input-->
<!--          v-model="queryParams.name"-->
<!--          placeholder="请输入公司全称"-->
<!--          clearable-->
<!--          @keyup.enter="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="简称" prop="shortName">-->
<!--        <el-input-->
<!--          v-model="queryParams.shortName"-->
<!--          placeholder="请输入简称"-->
<!--          clearable-->
<!--          @keyup.enter="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item>-->
<!--        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>-->
<!--        <el-button icon="Refresh" @click="resetQuery">重置</el-button>-->
<!--      </el-form-item>-->
<!--    </el-form>-->

<!--    <el-row :gutter="10" class="mb8">-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          plain-->
<!--          icon="Plus"-->
<!--          @click="handleAdd"-->
<!--          v-hasPermi="['scm:scmMyCompanyInfo:add']"-->
<!--        >新增</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="Edit"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['scm:scmMyCompanyInfo:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="danger"-->
<!--          plain-->
<!--          icon="Delete"-->
<!--          :disabled="multiple"-->
<!--          @click="handleDelete"-->
<!--          v-hasPermi="['scm:scmMyCompanyInfo:remove']"-->
<!--        >删除</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          plain-->
<!--          icon="Download"-->
<!--          @click="handleExport"-->
<!--          v-hasPermi="['scm:scmMyCompanyInfo:export']"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
<!--      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>-->
<!--    </el-row>-->

<!--    <el-table v-loading="loading" :data="scmMyCompanyInfoList" @selection-change="handleSelectionChange">-->
<!--      <el-table-column type="selection" width="55" align="center" />-->
<!--      <el-table-column label="ID" align="center" prop="id" />-->
<!--      <el-table-column label="公司全称" align="center" prop="name" />-->
<!--      <el-table-column label="简称" align="center" prop="shortName" />-->
<!--      <el-table-column label="统一社会信用代码" align="center" prop="registerNo" />-->
<!--      <el-table-column label="开户行名称" align="center" prop="bankName" />-->
<!--      <el-table-column label="开户账号" align="center" prop="bankAccount" />-->
<!--      <el-table-column label="联系人名称" align="center" prop="contactName" />-->
<!--      <el-table-column label="接收邮箱" align="center" prop="email" />-->
<!--      <el-table-column label="手机号码" align="center" prop="phone" />-->
<!--      <el-table-column label="地址" align="center" prop="address" />-->
<!--      <el-table-column label="税号" align="center" prop="taxNo" />-->
<!--      <el-table-column label="备注" align="center" prop="remarks" />-->
<!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">-->
<!--        <template #default="scope">-->
<!--          <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['scm:scmMyCompanyInfo:edit']">修改</el-button>-->
<!--          <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['scm:scmMyCompanyInfo:remove']">删除</el-button>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--    </el-table>-->
<!--    -->
<!--    <pagination-->
<!--      v-show="total>0"-->
<!--      :total="total"-->
<!--      v-model:page="queryParams.pageNum"-->
<!--      v-model:limit="queryParams.pageSize"-->
<!--      @pagination="getList"-->
<!--    />-->

    <!-- 添加或修改本公司信息对话框 -->
<!--    <el-dialog :title="title" v-model="open" width="500px" append-to-body>-->
<!--      <el-form ref="scmMyCompanyInfoRef" :model="form" :rules="rules" label-width="80px">-->
<!--        <el-form-item label="公司全称" prop="name">-->
<!--          <el-input v-model="form.name" placeholder="请输入公司全称" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="简称" prop="shortName">-->
<!--          <el-input v-model="form.shortName" placeholder="请输入简称" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="统一社会信用代码" prop="registerNo">-->
<!--          <el-input v-model="form.registerNo" placeholder="请输入统一社会信用代码" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="开户行名称" prop="bankName">-->
<!--          <el-input v-model="form.bankName" placeholder="请输入开户行名称" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="开户账号" prop="bankAccount">-->
<!--          <el-input v-model="form.bankAccount" placeholder="请输入开户账号" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="联系人名称" prop="contactName">-->
<!--          <el-input v-model="form.contactName" placeholder="请输入联系人名称" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="接收邮箱" prop="email">-->
<!--          <el-input v-model="form.email" placeholder="请输入接收邮箱" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="手机号码" prop="phone">-->
<!--          <el-input v-model="form.phone" placeholder="请输入手机号码" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="地址" prop="address">-->
<!--          <el-input v-model="form.address" placeholder="请输入地址" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="税号" prop="taxNo">-->
<!--          <el-input v-model="form.taxNo" placeholder="请输入税号" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="备注" prop="remarks">-->
<!--          <el-input v-model="form.remarks" placeholder="请输入备注" />-->
<!--        </el-form-item>-->
<!--      </el-form>-->
<!--      <template #footer>-->
<!--        <div class="dialog-footer">-->
<!--          <el-button type="primary" @click="submitForm">确 定</el-button>-->
<!--          <el-button @click="cancel">取 消</el-button>-->
<!--        </div>-->
<!--      </template>-->
<!--    </el-dialog>-->
  </div>
</template>

<script setup name="ScmMyCompanyInfo">
import { listScmMyCompanyInfo, getScmMyCompanyInfo, delScmMyCompanyInfo, addScmMyCompanyInfo, updateScmMyCompanyInfo } from "@/api/scm/scmMyCompanyInfo";

const { proxy } = getCurrentInstance();

const scmMyCompanyInfoList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const disabledForm = ref(true);
const formBk = ref({});

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    name: null,
    shortName: null,
  },
  rules: {
  }
});

const { queryParams, form, rules } = toRefs(data);

/** 查询本公司信息列表 */
function getList() {
  loading.value = true;
  listScmMyCompanyInfo(queryParams.value).then(response => {
    // scmMyCompanyInfoList.value = response.rows;
    // total.value = response.total;
    form.value = response.rows[0];
    loading.value = false;
  });
}

// 取消按钮
function cancel() {
  // open.value = false;
  // reset();
  disabledForm.value = true;
  form.value = JSON.parse(JSON.stringify(formBk.value));
}

// 表单重置
function reset() {
  form.value = {
    id: null,
    name: null,
    shortName: null,
    registerNo: null,
    bankName: null,
    bankAccount: null,
    contactName: null,
    email: null,
    phone: null,
    address: null,
    taxNo: null,
    remarks: null,
    createBy: null,
    createTime: null,
    updateBy: null,
    updateTime: null
  };
  proxy.resetForm("scmMyCompanyInfoRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 新增按钮操作 */
function handleAdd() {
  reset();
  open.value = true;
  title.value = "添加本公司信息";
}

/** 修改按钮操作 */
function handleUpdate(row) {
  reset();
  const _id = row.id || ids.value
  getScmMyCompanyInfo(_id).then(response => {
    form.value = response.data;
    open.value = true;
    title.value = "修改本公司信息";
  });
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["scmMyCompanyInfoRef"].validate(valid => {
    if (valid) {
      if (form.value.id != null) {
        updateScmMyCompanyInfo(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功");
          // open.value = false;
          disabledForm.value = true;
          getList();
        });
      } else {
        addScmMyCompanyInfo(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功");
          // open.value = false;
          disabledForm.value = true;
          getList();
        });
      }
    }
  });
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _ids = row.id || ids.value;
  proxy.$modal.confirm('是否确认删除本公司信息编号为"' + _ids + '"的数据项？').then(function() {
    return delScmMyCompanyInfo(_ids);
  }).then(() => {
    getList();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => {});
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('scm/scmMyCompanyInfo/export', {
    ...queryParams.value
  }, `scmMyCompanyInfo_${new Date().getTime()}.xlsx`)
}
/** 修改按钮操作 */
function handleEdit(){
  formBk.value = formBk.value = JSON.parse(JSON.stringify(form.value));
  disabledForm.value = false;
}

getList();
</script>
